//
//  BSKBookContentViewController.m
//  MicroMemory
//
//  Created by rimi on 16/7/22.
//  Copyright © 2016年 BlueSky. All rights reserved.
//

#import "BSKBookContentViewController.h"
#import "BSKNote.h"
#import "BSKTheme.h"
#import "BSKconsts.h"
#import "UIView+SDAutoLayout.h"
#import "BSKWeatherPicker.h"
@interface BSKBookContentViewController ()
@property(nonatomic,strong) UILabel * titleLabel;
@property(nonatomic,strong) UILabel * dateLabel;
@property(nonatomic,strong) UILabel * placeLabel;
@property(nonatomic,strong) UIView * titleBGView;
@property(nonatomic,strong) UITextView * contentTextview;
@property(nonatomic,strong) UILabel * pageLabel;
@property(nonatomic,strong) UIImageView * weatherImage;
@property(nonatomic,assign) NSInteger curentindex;
@end



@implementation BSKBookContentViewController

- (instancetype)initWithBounds:(CGRect)bounds
{
	self = [super init];
	if (self) {
		self.view.bounds = bounds;
		[self loadUI];
	}
	return self;
}

-(void)setVCWithNote:(BSKNote *)note index:(NSInteger)index indexCount:(NSInteger)count{
	_titleLabel.text = note.title;
	_dateLabel.text = note.date;
	_placeLabel.text = note.address;
	NSString * noteDirPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
	NSData * data = [NSData dataWithContentsOfFile:[NSString stringWithFormat:@"%@/%@",noteDirPath,note.noteFileName]];
	NSAttributedString * content =[[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute:NSRTFDTextDocumentType} documentAttributes:nil error:nil];
	_contentTextview.attributedText = content;
	_pageLabel.text = [NSString stringWithFormat:@"%ld/%ld",(long)index,(long)count];
	_weatherImage.image = [UIImage imageNamed:[BSKWeatherPicker getWeatherImageNameWithType:note.weatherType]];
}

-(void)loadUI{
	self.view.backgroundColor = [UIColor whiteColor];
	CGFloat startY = self.view.bounds.size.height/2 - 60*3;
	for (NSInteger index = 0; index<6; index ++) {
		UIImageView * ringImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ring"]];
		ringImage.frame = CGRectMake(-10, startY+60 * index, 25, 25);
		ringImage.contentMode = UIViewContentModeScaleToFill;
		[self.view addSubview:ringImage];
	}
	_titleBGView = [[UIView alloc]initWithFrame:CGRectMake(0, NavigationBarHeight, ScreenWidth - 20, 30)];
	_titleBGView.backgroundColor = [BSKTheme curentTheme].themeColor;
	[self.view addSubview:_titleBGView];
	_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, ScreenWidth - 60, 30)];
	[_titleBGView addSubview:_titleLabel];
	_titleLabel.textColor = [UIColor whiteColor];
	_titleLabel.font = [UIFont systemFontOfSize:25];
	
	_weatherImage = [[UIImageView alloc]init];
	_placeLabel = [[UILabel alloc]init];
	_dateLabel = [[UILabel alloc]init];
	_contentTextview = [[UITextView alloc]init];
	_pageLabel = [[UILabel alloc]init];
	
	[self.view addSubview:_placeLabel];
	[self.view addSubview:_dateLabel];
	[self.view addSubview:_contentTextview];
	[self.view addSubview:_pageLabel];
	[self.titleBGView addSubview:_weatherImage];
	
	_weatherImage.sd_layout
	.centerYEqualToView(self.titleBGView)
	.leftSpaceToView(self.titleBGView,10)
	.widthIs(20)
	.heightIs(20);
	
	_dateLabel.sd_layout
	.topSpaceToView(self.titleBGView,5)
	.leftSpaceToView(self.view,10)
	.rightSpaceToView(self.view,10)
	.heightIs(10);
	_dateLabel.textAlignment = NSTextAlignmentLeft;
	_dateLabel.font = [UIFont systemFontOfSize:10];
	_dateLabel.text = @"2016-07-24";
	
	_placeLabel.sd_layout
	.topSpaceToView(self.dateLabel,0)
	.leftSpaceToView(self.view,10)
	.rightSpaceToView(self.view,10)
	.heightIs(20);
	_placeLabel.text = @"未知地址";
	_placeLabel.textAlignment = NSTextAlignmentLeft;
	_placeLabel.font = [UIFont systemFontOfSize:10];
	_placeLabel.layer.borderColor = [[BSKTheme curentTheme].themeColor CGColor];
	_placeLabel.layer.borderWidth = 1;
	CALayer * masklayer = [CALayer layer];
	masklayer.frame = CGRectMake(1, 1, self.view.width-22, 20);
	masklayer.backgroundColor =[[UIColor blueColor] CGColor];
	_placeLabel.layer.mask = masklayer;
	
	_contentTextview.sd_layout
	.leftSpaceToView(self.view,15)
	.rightSpaceToView(self.view,0)
	.bottomSpaceToView(self.view,15)
	.topSpaceToView(_placeLabel,5);
	_contentTextview.editable = NO;
	_contentTextview.backgroundColor = [UIColor clearColor];
	_contentTextview.transform = CGAffineTransformMakeScale(0.98, 0.98);
	
	_pageLabel.sd_layout
	.centerXIs(self.view.width/2)
	.topSpaceToView(self.contentTextview,5)
	.widthIs(self.view.width)
	.heightIs(10);
	_pageLabel.textAlignment = NSTextAlignmentCenter;
	_pageLabel.font = [UIFont systemFontOfSize:10];
	
}

- (void)viewDidLoad{
    [super viewDidLoad];
	    // Do any additional setup after loading the view.
}


@end
